home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 3.5 KB | 182 lines | [TEXT/CWIE] |
- // WindowObject.cp
-
- #ifndef WindowObject_h
- #include "WindowObject.h"
- #endif
- #ifndef MemoryFullError_h
- #include "MemoryFullError.h"
- #endif
- #ifndef GraphicsDeviceObject_h
- #include "GraphicsDeviceObject.h"
- #endif
-
- WindowObject::WindowObject( Definition definition,
- bool withClosebox )
- {
- static Rect defaultBounds = { 30, 30, 130, 130 };
-
- GrafPort *result = NewCWindow( reinterpret_cast<Ptr>( &port ),
- &defaultBounds,
- "\p",
- false,
- definition,
- 0,
- withClosebox,
- 0 );
-
- if ( result == 0 )
- throw MemoryFullError();
-
- Assert( result == &port );
- SetPort( result );
- }
-
- PointObject WindowObject::SizeByDragging( PointObject mouse,
- PointObject minimum,
- PointObject maximum )
- {
- // GrowWindow doesn't let you acheive the maximum:
- if ( maximum.h < maxint16 )
- maximum.h++;
- if ( maximum.v < maxint16 )
- maximum.v++;
-
- Rectangle bounds( minimum.h,
- minimum.v,
- maximum.h,
- maximum.v );
-
- uint32 result = GrowWindow( &port, mouse, &bounds );
-
- if ( result == 0 )
- return Size();
-
- return PointObject( Word0( result ), Word1( result ) );
- }
-
- void WindowObject::SetBounds( Rectangle newBounds )
- {
- Rectangle oldBounds( GlobalBounds() );
-
- if ( newBounds == oldBounds )
- return;
-
- if ( newBounds.TopLeft() != oldBounds.TopLeft() )
- SetPosition( newBounds.TopLeft() );
-
- if ( newBounds.Size() != oldBounds.Size() )
- SetSize( newBounds.Size() );
- }
-
- void WindowObject::ZoomToUserBounds()
- {
- ZoomWindow( &port, inZoomIn, false );
- InvalRect( &port.portRect );
- }
-
- void WindowObject::ZoomToStandardBounds()
- {
- ZoomWindow( &port, inZoomOut, false );
- InvalRect( &port.portRect );
- }
-
- WStateData& WindowObject::StateData()
- {
- Assert( dataHandle != 0 );
- Assert( *dataHandle != 0 );
- return **reinterpret_cast<WStateData **>( dataHandle );
- }
-
- const WStateData& WindowObject::StateData() const
- {
- Assert( dataHandle != 0 );
- Assert( *dataHandle != 0 );
- return **reinterpret_cast<WStateData **>( dataHandle );
- }
-
- uint32 WindowObject::Index() const
- {
- Assert( Visible() );
-
- if ( !Visible() )
- throw OSError( errAENoSuchObject );
-
- uint32 index = 1;
- for ( WindowObject *w = Front(); w != 0; w = w->Next() )
- {
- if ( !w->Visible() )
- continue;
-
- if ( w == this )
- return index;
-
- index++;
- }
-
- Assert( 0 );
- throw OSError( errAENoSuchObject );
- return 0;
- }
-
- void WindowObject::SetIndex( uint32 newIndex )
- {
- Assert( newIndex > 0 );
- if ( newIndex == 0 )
- throw OSError( errAEIllegalIndex );
-
- if ( newIndex == 1 )
- Select();
- else
- {
- WindowObject *w = Front();
-
- while ( w != 0 && newIndex > 2 )
- {
- if ( w->Visible() )
- newIndex--;
-
- w = w->Next();
- }
-
- if ( w == 0 )
- throw OSError( errAEIllegalIndex );
-
- SendBehind( *w );
- }
-
- if ( !Visible() )
- Show();
- }
-
- GDHandle WindowObject::NearestScreen() const
- {
- return GraphicsDeviceObject::Nearest( GlobalBounds() );
- }
-
- GDHandle WindowObject::DeepestScreen() const
- {
- return GraphicsDeviceObject::Deepest( GlobalBounds() );
- }
-
- uint32 WindowObject::CountVisibleWindows()
- {
- uint32 count = 0;
-
- for ( WindowObject *w = Front(); w != 0; w = w->Next() )
- if ( w->Visible() )
- count++;
-
- return count;
- }
-
- uint32 WindowObject::CountVisibleWindows( Rectangle target )
- {
- uint32 count = 0;
-
- for ( WindowObject *w = Front(); w != 0; w = w->Next() )
- if ( w->Visible() && target.Contains( w->GlobalBounds().TopLeft() ) )
- count++;
-
- return count;
- }
-